package com.houxy.service.impl;

import com.houxy.repository.mapper.DepartmentMapper;
import com.houxy.repository.model.entity.Department;
import com.houxy.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Hou
 * @date 2019/3/18 15:52
 * @describe：
 */
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {


    @Autowired
    private DepartmentMapper departmentMapper;


    @Override
    public boolean addDepartment(Department department) {
        department.setIsDelete(0);
        int insert = departmentMapper.insertSelective(department);
        if (insert > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<Department> findAllDepartment() {
        return departmentMapper.findAll();
    }

    @Override
    public boolean deleteDepartment(int departmentId) {
        Department department = findById(departmentId);
        if (department != null) {
            department.setIsDelete(1);
        }
        int update = departmentMapper.updateByPrimaryKeySelective(department);
        if (update > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Department findById(int departmentId) {
        return departmentMapper.selectByPrimaryKey(departmentId);
    }
}
